package jetbrains.lb.refik;

import com.intellij.openapi.util.TextRange;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.psi.*;
import com.intellij.psi.xml.XmlElement;
import org.jetbrains.annotations.NotNull;



/**
 * Created by IntelliJ IDEA.
 * User: Leonid.Bushuev
 * Date: 17.09.2010
 * Time: 12:13:04
 * To change this template use File | Settings | File Templates.
 */
public class RefikPsiReference extends PsiReferenceBase<XmlElement>
{

    public RefikPsiReference(XmlElement element)
    {
        super(element);
    }


    @Override
    public PsiElement resolve() {
        String packageName = getPackageName();

        String shortName = getValue();
        String qualifiedName = StringUtil.getQualifiedName(packageName, shortName);
        PsiClass aClass = getPsiFacade().findClass(qualifiedName, myElement.getResolveScope());
        return aClass;
    }


    private JavaPsiFacade getPsiFacade() {return JavaPsiFacade.getInstance(myElement.getProject());}


    private String getPackageName() {return "xxx.yyy.zzz";}


    @NotNull
    @Override
    public Object[] getVariants()
    {
        PsiPackage aPackage = getPsiFacade().findPackage(getPackageName());
        PsiClass[] classes = aPackage.getClasses(myElement.getResolveScope());
        return classes;
    }
}
